#coding=utf-8
#Boa:Frame:FrameStaff

import wx

import DlgStaffEditor, DlgOperatorEditor

from ctrlAider import *
from product import CDataStaff

def create(parent):
    return FrameStaff(parent)

[wxID_FRAMESTAFF, wxID_FRAMESTAFFBTNADD, wxID_FRAMESTAFFBTNDEL, 
 wxID_FRAMESTAFFBTNMODIFY, wxID_FRAMESTAFFBTNSETOPERATOR, 
 wxID_FRAMESTAFFLCSTAFF, 
] = [wx.NewId() for _init_ctrls in range(6)]

class FrameStaff(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAMESTAFF, name=u'FrameStaff',
              parent=prnt, pos=wx.Point(460, 224), size=wx.Size(707, 442),
              style=wx.DEFAULT_FRAME_STYLE, title=u'\u5458\u5de5\u4fe1\u606f')
        self.SetClientSize(wx.Size(699, 408))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))
        self.Center(wx.BOTH)

        self.btnAdd = wx.Button(id=wxID_FRAMESTAFFBTNADD, label=u'\u65b0\u589e',
              name=u'btnAdd', parent=self, pos=wx.Point(24, 32),
              size=wx.Size(75, 24), style=0)
        self.btnAdd.Bind(wx.EVT_BUTTON, self.OnBtnAddButton,
              id=wxID_FRAMESTAFFBTNADD)

        self.btnModify = wx.Button(id=wxID_FRAMESTAFFBTNMODIFY,
              label=u'\u4fee\u6539', name=u'btnModify', parent=self,
              pos=wx.Point(128, 32), size=wx.Size(75, 24), style=0)
        self.btnModify.Bind(wx.EVT_BUTTON, self.OnBtnModifyButton,
              id=wxID_FRAMESTAFFBTNMODIFY)

        self.btnDel = wx.Button(id=wxID_FRAMESTAFFBTNDEL, label=u'\u5220\u9664',
              name=u'btnDel', parent=self, pos=wx.Point(432, 32),
              size=wx.Size(75, 24), style=0)
        self.btnDel.Bind(wx.EVT_BUTTON, self.OnBtnDelButton,
              id=wxID_FRAMESTAFFBTNDEL)

        self.lcStaff = wx.ListCtrl(id=wxID_FRAMESTAFFLCSTAFF, name=u'lcStaff',
              parent=self, pos=wx.Point(24, 72), size=wx.Size(648, 304),
              style=wx.LC_VRULES | wx.LC_HRULES | wx.LC_REPORT)

        self.btnSetOperator = wx.Button(id=wxID_FRAMESTAFFBTNSETOPERATOR,
              label=u'\u8bbe\u7f6e\u64cd\u4f5c\u5458', name=u'btnSetOperator',
              parent=self, pos=wx.Point(224, 32), size=wx.Size(75, 24),
              style=0)
        self.btnSetOperator.Bind(wx.EVT_BUTTON, self.OnBtnSetOperatorButton,
              id=wxID_FRAMESTAFFBTNSETOPERATOR)

    def __init__(self, parent):
        self._init_ctrls(parent)

        self.myInit()
        
    def myInit(self):
        cols = [(CDataStaff.COL_ID, wx.LIST_FORMAT_LEFT, 0),
                (CDataStaff.COL_NAME, wx.LIST_FORMAT_LEFT, -1),
                (CDataStaff.COL_POST, wx.LIST_FORMAT_LEFT, -1),
                (CDataStaff.COL_ISOPERATOR, wx.LIST_FORMAT_LEFT, -1),
                (CDataStaff.COL_PHONE, wx.LIST_FORMAT_LEFT, -1),
                (CDataStaff.COL_ADDR, wx.LIST_FORMAT_LEFT, -1),
                (CDataStaff.COL_EMERGENCY, wx.LIST_FORMAT_LEFT, -1),
                (CDataStaff.COL_MEMO, wx.LIST_FORMAT_LEFT, -1)]
        
        self.listStaff = MyListCtrlDecorator(self.lcStaff, cols, CDataStaff)
        
    def OnBtnAddButton(self, event):
        dlg = DlgStaffEditor.create(self)
        dlg.ShowModal()
        self.listStaff.refresh()

    def getSelStaff(self):
        item = self.listStaff.getSeletion()
        if (item == -1):
            return None
        
        val = int(self.listStaff.getItem(item, 0))
        return CDataStaff.getFirstInstance({CDataStaff.COL_ID:val})
        
    def OnBtnModifyButton(self, event):
        staffObj = self.getSelStaff()
        if (staffObj is None):
            dlg = wx.MessageDialog(self, u'请选择列表项目', u'提示',
                                    wx.OK|wx.ICON_ERROR)
            dlg.ShowModal()
            return
        
        dlg = DlgStaffEditor.create(self)
        dlg.setStaff(staffObj)
        dlg.ShowModal()
        self.listStaff.refresh()

    def OnBtnDelButton(self, event):
        staffObj = self.getSelStaff()
        if (staffObj is None):
            dlg = wx.MessageDialog(self, u'请选择列表项目', u'提示',
                                    wx.OK|wx.ICON_ERROR)
            dlg.ShowModal()
            return
        
        staffObj.delete()
        self.listStaff.refresh()

    def OnBtnSetOperatorButton(self, event):
        staffObj = self.getSelStaff()
        if (staffObj is None):
            dlg = wx.MessageDialog(self, u'请选择列表项目', u'提示',
                                    wx.OK|wx.ICON_ERROR)
            dlg.ShowModal()
            return
        
        dlg = DlgOperatorEditor.create(self)
        dlg.setStaff(staffObj)
        dlg.ShowModal()
        self.listStaff.refresh()
